# 396. 旋转函数
from typing import List
import json

# 方法一：迭代
class Solution:
    def maxRotateFunction(self, nums: List[int]) -> int:
        f, n, numSum = 0, len(nums), sum(nums)
        for i, num in enumerate(nums):
            f += i * num
        res = f
        for i in range(n - 1, 0, -1):
            f = f + numSum - n * nums[i]
            res = max(res, f)
        return res


if __name__ == '__main__':
    nums = json.loads(input().strip())
    solution = Solution()
    print(solution.maxRotateFunction(nums))

"""
不理解的地方：
定义nums的旋转函数F为：
F(k) = 0 * arrk[0] + 1 * arrk[1] + ... + (n - 1) * arrk[n - 1]

"""